home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / dxf2tri.zip / DXF2TRI.DOC < prev    next >
Text File  |  1993-08-10  |  9KB  |  166 lines

  1.                                  DXF2TRI
  2.                 DXF polyline/polygon to triangle converter
  3.                          by Tim Riley   Aug 1993
  4.                                 based on
  5.                 POLY2TRI - a polygon to triangle converter
  6.                          by Steve Anger Jan 1993
  7.  
  8. This program is commited to the public domain. Feel free to use all or part
  9. of this code in your own programs.
  10.  
  11. This is a utility that extracts polyline shapes from a DXF file and breaks
  12. them down into individual triangles. The polylines are assumed to be closed,
  13. planar (2D) polygons. This program only deals with POLYLINE entities and
  14. ignores all other entities in the DXF file. All properties (color, line type)
  15. are ignored. 
  16.  
  17. The input DXF file consists of one or more polylines with no more than 2000
  18. vertices. This limit is rather arbitrary and can be changed if necessary by
  19. changing POLYMAX.
  20.  
  21. The program uses the following syntax:
  22.  
  23.         DXF2TRI infile[.DXF] [outfile[.RAW]] [-e] [-b]
  24.  
  25. with two options:
  26.         -e:     extrude the object one unit in the z direction (use SCALE
  27.                 in the scene descriptor file to modify this). The extrusion
  28.                 is only applied to the edge of the object, not to the in-
  29.                 dividual triangles.
  30.         -b:     generate a back to the extruded object. This is useful if
  31.                 the back will be visible (ex: in a reflection). This option
  32.                 can be used without the -e option for whatever reason.
  33.  
  34. The output file consists of one triangle per line in the following format:
  35.  
  36.                       x1 y1 z1 x2 y2 z2 x3 y3 z3
  37.  
  38. and can be fed directly into RAW2POV to create an INC file with calculated
  39. bounding shapes (which speeds up tracing) and a POV file which gives limits
  40. of the total object to aid in positioning. RAW2POV converts some triangles
  41. (the extrusions) to smooth traingles, which gives a nice look to the sides.
  42.  
  43. NOTE:   the resultant object is a shell, not a solid, so take this into
  44.         account when applying textures, particularly wood and marble. Also,
  45.         the object won't work with CSG.
  46.  
  47. So much for the boilerplate. The reason this came about was the result of
  48. a quest for ray-tracing's holy grail: neat-o text in a scene. I struggled
  49. along for a while until I came across Steve Anger's POLY2TRI program. The
  50. seas parted, the clouds lifted and my sinuses cleared. Thanks Steve.
  51.  
  52. This archive should contain the following:
  53.  
  54.         DXF2TRI.C       The source
  55.         DXF2TRI.EXE     The executable, compiled with Borland C++ 2.1, large
  56.                         memory model (if I remember correctly). No extenders,
  57.                         no memory tricks, so you don't have to worry about
  58.                         EMM386 and it's ilk and it runs fine from within
  59.                         Windows.
  60.         DXF2TRI.DOC     Duh, guess.
  61.         TEST.JPG        A sample 640x480 image. It took 9m19s to trace on a
  62.                         HP9000/710 file server (UNIX, with everybody else
  63.                         doing their thing as well).
  64.  
  65. To keep things straight forward, here is how I put text in a scene (NOTE:
  66. I am assuming a reasonable knowledge of CorelDraw. This method should be
  67. possible with other Windows draw (NOT paint) programs such as Micrographix,
  68. Adobe Draw (Designer?) and others, none of which I have any experience with,
  69. assuming they have the following capabilities:
  70.         *        can export a DXF file
  71.         *        converts curves to line segments (POLYLINES)
  72. otherwise, you're out of luck):
  73.  
  74. 1.      Use Corel (4.0) to generate the initial text. Overall size and
  75.         position is not important since you will scale and position it later
  76.         on. Line properties (type, thickness or color) are irrelevant since
  77.         they will be ignored, as well as fill properties.
  78.  
  79. 2.      Dealing with holes: re-entrant (concave) portions of a letter appear
  80.         to convert with no problems (the m and & of the test image seem to
  81.         prove this). Holes are another matter. In the simplest view, they are
  82.         another object/curve. Since the objects will be converted to 2D
  83.         triangles, CSG cannot be used to subtract them from the main object.
  84.         The easiest solution I have found is to make all holes part of the
  85.         main object's outline. This is accomplished in two steps:
  86.         a.      Convert the letter from text to a curve. Do this after you
  87.                 have done all of the transformations you care to do on your
  88.                 text. You cannot convert from curves back to text (well you
  89.                 can, in a way, but font creation is beyond to scope of this
  90.                 babble).
  91.         b.      Using the node edit tool, cut a channel of zero width between
  92.                 the hole and the outside of the curve/letter. This can be done
  93.                 anywhere. As long as the sides of the channel touch, there will
  94.                 be no visible effect on the finished product. For example:
  95.                 Turn:                           into:
  96.                              ***                            ***
  97.                           ***   ***                      ***   ***
  98.                         **         **                  **         **
  99.                       **     ***     **              **     ***     **
  100.                      *     **   **     *            *     **   **     *
  101.                     *    **       **    *          *    **       **    *
  102.                     *   *           *   *          *   *           *   *
  103.                     *   *           *   *          *   *           *   *
  104.                     *   *           *   *          *   *           *   *
  105.                     *    **       **    *          *    **       **    *
  106.                      *     **   **     *            *     **   **     *
  107.                       **     ***     **              **     * *     **
  108.                         **         **                  **   * *   **
  109.                           ***   ***                      **** ****
  110.                              ***                            * *
  111.                                 These segements overlap --->| |<---
  112.  
  113.                 If you want to be artistic, you can cut the channels in
  114.                 obvious places, where a curve intersects a straight segment,
  115.                 for example. I broke the ampersand in the following places:
  116.  
  117.                         ***
  118.                        *   *
  119.                        *   *
  120.                         * \
  121.                         \*
  122.                        *  * *
  123.                       *    *
  124.                       *   * *
  125.                        * *   *
  126.  
  127.                 and then removed the unnecessary nodes on the straight line
  128.                 segments. This has the added effect of reducing the number of
  129.                 vertices of the polyline, as well as the number of triangles
  130.                 and the complexity of the final object.
  131.  
  132. 3.      Export the text as a DXF file. The Corel 4.0 DXF filter converts all
  133.         curves to line segments. It allows you to choose the number of line
  134.         segments a curve is converted to. I chose 32 (the minimum value) to
  135.         minimize the complexity of the object. There is no visible degradation
  136.         to the object when rendered at 1024x768 (and, I suspect, greater).
  137.         Individual letters may be exported to separate DXF files if you want
  138.         to texture them separately. The COREL-DXF-RAW-POV conversion chain
  139.         retains the relative position of each letter, but they become separate
  140.         objects and inter-letter spacing becomes a problem unless you first
  141.         combine them as a composite in the scene file before performing any
  142.         transformation. If you are going to texture the text uniformly, it
  143.         is easier to export the text to a single DXF file and treat it as a
  144.         single object.
  145.  
  146. 4.      Run DXF2TRI on the DXF file to generate a RAW file. If you want to
  147.         extrude the letters, use the -e switch. If the back of the letters will
  148.         be visible (due to reflections or camera position), use the -b switch
  149.         to generate solid backs to the letters.
  150.  
  151. 5.      Run RAW2POV on the RAW file. RAW2POV will generate a POV file giving
  152.         the physical limits of the object(s) and an INC file consisting of
  153.         triangles, smooth triangles and bounding shapes. The rest is up to you.
  154.  
  155. No, its not overly easy or straight forward, but it works well and the results
  156. aren't bad. Before anyone has a chance to ask or comment, no it won't bevel,
  157. but I am thinking of it. A straight bevel should be possible, but a curved
  158. (routed) bevel will take some doing, since CSG won't work with triangles. Don't
  159. let me stop anyone else from working on the problem, since I have a lot of
  160. other things to keep me busy.
  161.  
  162. I assume NO responsibility for this program or its effects, but if you need to
  163. contact me, for whatever reason, I check in occasionally to The Graphics
  164. Alternative and my Internet address is: triley@its.bldrdoc.gov.
  165.  
  166. Doo dah.